#include <deque>
#include <queue>

using namespace std;

class MaxQueue {
private:
    queue<int> queue;
    deque<int> deque;
public:
    MaxQueue() {

    }

    int max_value() {
        return deque.empty() ? -1 : deque.front();
    }

    void push_back(int value) {
        queue.push(value);
        while (!deque.empty() && deque.back() < value) {
            deque.pop_back();
        }
        deque.push_back(value);
    }

    int pop_front() {
        if (queue.empty()) {
            return -1;
        }
        int ans = queue.front();
        queue.pop();
        if (deque.front() == ans) {
            deque.pop_front();
        }
        return ans;
    }
};
